package com.webcash.CNBoard.Interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.webcash.CNBoard.Model.Login;

public class LoginCheckInterceptor extends HandlerInterceptorAdapter {

	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {

		// session 검사
		HttpSession session = request.getSession(false);

		Login login = (Login) session.getAttribute("login");

		if (login == null) {
			response.sendRedirect(request.getContextPath() + "/login");
			return false;
		}

		String id = (String) login.getId();
		if (id == null) {
			response.sendRedirect(request.getContextPath() + "/login");
			return false;
		}

		return true;
	}

}
